import axios from 'axios'
export default {
  // 开启命名空间
  namespaced: true,

  state () {
    return {
      // 购物车默认为空
      cartList: []
    }
  },

  mutations: {
    // 给cartList赋值的方法
    setCartList (state, list) {
      state.cartList = list
    }
  },

  actions: {
    async reqCartList (ctx) {
      // 在这里发请求
      const res = await axios({
        url: 'http://localhost:3000/cart'
      })

      ctx.commit('setCartList', res.data)
    }
  }
}
